type ReplaceAll<
  S extends string,
  From extends string,
  To extends string
> = From extends ""
  ? S
  : S extends `${infer R}${From}${infer K}`
  ? `${R}${To}${ReplaceAll<K, From, To>}`
  : S;

// ReplaceAll<"t y p e s", " ", "">  types  ReplaceAll<`${R}${To}${K}`, From, To>

// ReplaceAll<"foobarfoobar", "ob", "b">, "fobarfobar"
//            fobarfoobar
//            fbarfoobar
//            fbarfobar
